class Solution {
public:
    int reverse(int x) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
    	bool sign = x < 0 ? true : false;
		long long v = x;
		if (v < 0) {
			v = -v;
		}

		long long result = 0;
		while (v > 0) {
			result = result * 10 + v % 10;
			v /= 10;
		}
		return sign ? -static_cast<int>(result) : static_cast<int>(result);

    }
};